<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>全 0 子数组的数目</title>
</head>
<body>
  <script>
    function fn(nums) {
      let ans = 0, cur = 0;
      for (const num of nums) {
        if (num === 0) {
          cur++;
        } else {
          if (cur) {
            ans += (1 + cur) * cur / 2;
            cur = 0;
          }
        }
      }
      if (cur) {
        ans += (1 + cur) * cur / 2;
      }
      return ans;
    }
    console.log(fn([1,3,0,0,2,0,0,4]))
  </script>
</body>
</html>